package pkg

import (
	"encoding/json"
	"fmt"
	"net/http"
)

// 调用
func ShiMing(realname, idcard string) bool {
	//创建一个请求
	client := http.Client{}
	//定义一个地址
	url := "https://eid.shumaidata.com/eid/check?idcard=" + idcard + "&name=" + realname
	//创建一个新的请求
	request, err := http.NewRequest("POST", url, nil)
	if err != nil {
		fmt.Println("创建请求失败", err)
		return false
	}
	//在head 里面添加数据
	request.Header.Add("Authorization", "APPCODE 312663d3abb8433f97f5db4789d9c99f")
	//先使用后关闭
	do, err := client.Do(request)
	defer do.Body.Close()

	var rets T2
	//解码
	err = json.NewDecoder(do.Body).Decode(&rets)
	if err != nil {
		fmt.Println("http解码失败", err)
		return false
	}

	if rets.Code == "0" && rets.Result.Res == "1" {
		return true
	}
	return false
}

type T2 struct {
	Code    string `json:"code"`
	Message string `json:"message"`
	Result  struct {
		Name        string `json:"name"`
		Idcard      string `json:"idcard"`
		Res         string `json:"res"`
		Description string `json:"description"`
		Sex         string `json:"sex"`
		Birthday    string `json:"birthday"`
		Address     string `json:"address"`
	} `json:"result"`
}
